package xman.mjava.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class FileUploadController {
    
    @RequestMapping(value = "/fupload", method = RequestMethod.POST)
    public String fupload(String name, MultipartFile file, HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        if (!file.isEmpty()) {
            byte[] bytes = file.getBytes();
            // store the bytes somewhere
            // 在这里就可以对file进行处理了，可以根据自己的需求把它存到数据库或者服务器的某个文件夹
            
            return "redirect:uploadSuccess";
        } else {
            return "redirect:uploadFailure";
        }
    }
    
}
